package com.work.dao.impl;

import com.work.bean.Student;
import com.work.bean.Teacher;
import com.work.dao.BaseDao;
import com.work.dao.TeacherDao;

import java.util.List;

public class TeacherDaoImpl extends BaseDao implements TeacherDao {
    public Teacher queryTeacherById(Integer id) {
        String sql = "SELECT * FROM t_teacher WHERE id = ? ";
        return  queryForOne(Teacher.class,sql,id);
    }

    public List<Teacher> queryTeacher() {
        String sql = "SELECT * FROM t_teacher  ";
        return queryForList(Teacher.class,sql);
    }

    public Teacher queryTeacherByUId(Integer uId) {
        String sql = "SELECT * FROM t_teacher WHERE uid = ? ";
        return  queryForOne(Teacher.class,sql,uId);
    }

    @Override
    public Teacher query() {
        String sql = "SELECT * FROM t_teacher ORDER BY id DESC LIMIT 1 ";
        return  queryForOne(Teacher.class,sql);
    }

    public int saveTeacher(Teacher teacher) {
        String sql = "INSERT INTO `t_teacher` (`uid`, `name`, `sex`, `age`, `pwd`) VALUES (?, ?, ?, ?, ?)";
        return update(sql,teacher.getuId(),teacher.getName(),teacher.getSex(),teacher.getAge(),teacher.getPwd());
    }

    public int updateTeacher(Teacher teacher) {
        String sql = "UPDATE t_teacher SET `uid`=?,`name`=?,`sex`=?,`age`=?,`pwd`=? WHERE `id` = ?";
        return update(sql,teacher.getuId(),teacher.getName(),teacher.getSex(),teacher.getAge(),teacher.getPwd(),teacher.getId());
    }

    public int updateTeacherPwdById(Teacher teacher) {
        String sql = "UPDATE t_teacher SET `pwd`=? WHERE `id` = ?";
        return update(sql,teacher.getPwd(),teacher.getId());
    }

    public int deleteTeacher(Integer id) {
        String sql = "DELETE FROM `t_teacher` WHERE `id` = ?";
        return update(sql, id);
    }
}
